<script lang="ts" setup>
import type { MenuStructure } from "@/api/menu.ts"

const editData = ref({
  name: "",
  url: "",
  pid: 0,
  icon: ""
})

const { data } = defineProps({
  data: {
    type: Object as PropType<MenuStructure>,
    default: () => {
      return {}
    }
  },
  type: {
    type: Number,
    required: true
  }
})

watchEffect(() => {
  if (data) {
    editData.value = { ...data }
  }
})

const emit = defineEmits(["submit"])
const handleSubmit = () => {
  emit("submit", editData.value)
}
</script>

<template>
  <el-form :model="editData" label-width="auto" style="max-width: 600px">
    <el-form-item label="名称">
      <el-input v-model="editData.name" placeholder="请输入用户名"></el-input>
    </el-form-item>
    <el-form-item label="pid">
      <el-input
        v-model="editData.pid"
        default="0"
        placeholder="请输入用户名"
      ></el-input>
    </el-form-item>
    <el-form-item label="路径">
      <el-input v-model="editData.url" placeholder="请输入url"></el-input>
    </el-form-item>
    <el-form-item label="图标">
      <el-input v-model="editData.icon" placeholder="请输入icon"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleSubmit">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<style scoped></style>
